<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Collapses the result set to a single document per group</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="solrquery.addstatsfield.html">« SolrQuery::addStatsField</a></li>
      <li style="float: right;"><a href="solrquery.construct.html">SolrQuery::__construct »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="class.solrquery.html">SolrQuery</a></li>
    <li>Collapses the result set to a single document per group</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="solrquery.collapse" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">SolrQuery::collapse</h1>
  <p class="verinfo">(No version information available, might only be in Git)</p><p class="refpurpose"><span class="refname">SolrQuery::collapse</span> &mdash; <span class="dc-title">Collapses the result set to a single document per group</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-solrquery.collapse-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><strong>SolrQuery::collapse</strong></span>(<span class="methodparam"><span class="type"><a href="class.solrcollapsefunction.html" class="type SolrCollapseFunction">SolrCollapseFunction</a></span> <code class="parameter">$collapseFunction</code></span>): <span class="type"><a href="class.solrquery.html" class="type SolrQuery">SolrQuery</a></span></div>

  <p class="para rdfs-comment">
     Collapses the result set to a single document per group before it forwards
     the result set to the rest of the search components.
  </p>
  <p class="para">
     So all downstream components (faceting, highlighting, etc...) will work with
     the collapsed result set.
  </p>

 </div>


 <div class="refsect1 parameters" id="refsect1-solrquery.collapse-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt>
<code class="parameter">collapseFunction</code></dt>

     <dd>

      <p class="para">
          
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-solrquery.collapse-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   Returns the current <span class="type"><a href="class.solrquery.html" class="type SolrQuery">SolrQuery</a></span> object
  </p>
 </div>

<div class="refsect1 examples" id="refsect1-solrquery.collapse-examples">
  <h3 class="title">范例</h3>
  <div class="example" id="example-4651">
   <p><strong>示例 #1 <span class="methodname"><strong>SolrQuery::collapse()</strong></span> example</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br /></span><span style="color: #007700">include&nbsp;</span><span style="color: #DD0000">"bootstrap.php"</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">$options&nbsp;</span><span style="color: #007700">=&nbsp;array<br />(<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'hostname'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">SOLR_SERVER_HOSTNAME</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'login'&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">SOLR_SERVER_USERNAME</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'password'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">SOLR_SERVER_PASSWORD</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'port'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">SOLR_SERVER_PORT</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'path'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">SOLR_SERVER_PATH<br /></span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$client&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">SolrClient</span><span style="color: #007700">(</span><span style="color: #0000BB">$options</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$query&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">SolrQuery</span><span style="color: #007700">(</span><span style="color: #DD0000">'*:*'</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$collapseFunction&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">SolrCollapseFunction</span><span style="color: #007700">(</span><span style="color: #DD0000">'manu_id_s'</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$collapseFunction<br /></span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">setSize</span><span style="color: #007700">(</span><span style="color: #0000BB">2</span><span style="color: #007700">)<br />-&gt;</span><span style="color: #0000BB">setNullPolicy</span><span style="color: #007700">(</span><span style="color: #0000BB">SolrCollapseFunction</span><span style="color: #007700">::</span><span style="color: #0000BB">NULLPOLICY_IGNORE</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$query<br /></span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">collapse</span><span style="color: #007700">(</span><span style="color: #0000BB">$collapseFunction</span><span style="color: #007700">)<br />-&gt;</span><span style="color: #0000BB">setRows</span><span style="color: #007700">(</span><span style="color: #0000BB">4</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$queryResponse&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$client</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">query</span><span style="color: #007700">(</span><span style="color: #0000BB">$query</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$response&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$queryResponse</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getResponse</span><span style="color: #007700">();<br /><br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">$response</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

   <div class="example-contents"><p>以上例程的输出类似于：</p></div>
        <div class="example-contents screen">
            <div class="cdata"><pre>
SolrObject Object
(
    [responseHeader] =&gt; SolrObject Object
        (
            [status] =&gt; 0
            [QTime] =&gt; 1
            [params] =&gt; SolrObject Object
                (
                    [q] =&gt; *:*
                    [indent] =&gt; on
                    [fq] =&gt; {!collapse field=manu_id_s size=2 nullPolicy=ignore}
                    [rows] =&gt; 4
                    [version] =&gt; 2.2
                    [wt] =&gt; xml
                )

        )

    [response] =&gt; SolrObject Object
        (
            [numFound] =&gt; 14
            [start] =&gt; 0
            [docs] =&gt; Array
                (
                    [0] =&gt; SolrObject Object
                        (
                            [id] =&gt; SP2514N
                            [name] =&gt; Array
                                (
                                    [0] =&gt; Samsung SpinPoint P120 SP2514N - hard drive - 250 GB - ATA-133
                                )

                            [manu] =&gt; Array
                                (
                                    [0] =&gt; Samsung Electronics Co. Ltd.
                                )

                            [manu_id_s] =&gt; samsung
                            [cat] =&gt; Array
                                (
                                    [0] =&gt; electronics
                                    [1] =&gt; hard drive
                                )

                            [features] =&gt; Array
                                (
                                    [0] =&gt; 7200RPM, 8MB cache, IDE Ultra ATA-133
                                    [1] =&gt; NoiseGuard, SilentSeek technology, Fluid Dynamic Bearing (FDB) motor
                                )

                            [price] =&gt; Array
                                (
                                    [0] =&gt; 92
                                )

                            [popularity] =&gt; Array
                                (
                                    [0] =&gt; 6
                                )

                            [inStock] =&gt; Array
                                (
                                    [0] =&gt; 1
                                )

                            [manufacturedate_dt] =&gt; 2006-02-13T15:26:37Z
                            [store] =&gt; Array
                                (
                                    [0] =&gt; 35.0752,-97.032
                                )

                            [_version_] =&gt; 1510294336412057600
                        )

                    [1] =&gt; SolrObject Object
                        (
                            [id] =&gt; 6H500F0
                            [name] =&gt; Array
                                (
                                    [0] =&gt; Maxtor DiamondMax 11 - hard drive - 500 GB - SATA-300
                                )

                            [manu] =&gt; Array
                                (
                                    [0] =&gt; Maxtor Corp.
                                )

                            [manu_id_s] =&gt; maxtor
                            [cat] =&gt; Array
                                (
                                    [0] =&gt; electronics
                                    [1] =&gt; hard drive
                                )

                            [features] =&gt; Array
                                (
                                    [0] =&gt; SATA 3.0Gb/s, NCQ
                                    [1] =&gt; 8.5ms seek
                                    [2] =&gt; 16MB cache
                                )

                            [price] =&gt; Array
                                (
                                    [0] =&gt; 350
                                )

                            [popularity] =&gt; Array
                                (
                                    [0] =&gt; 6
                                )

                            [inStock] =&gt; Array
                                (
                                    [0] =&gt; 1
                                )

                            [store] =&gt; Array
                                (
                                    [0] =&gt; 45.17614,-93.87341
                                )

                            [manufacturedate_dt] =&gt; 2006-02-13T15:26:37Z
                            [_version_] =&gt; 1510294336449806336
                        )

                    [2] =&gt; SolrObject Object
                        (
                            [id] =&gt; F8V7067-APL-KIT
                            [name] =&gt; Array
                                (
                                    [0] =&gt; Belkin Mobile Power Cord for iPod w/ Dock
                                )

                            [manu] =&gt; Array
                                (
                                    [0] =&gt; Belkin
                                )

                            [manu_id_s] =&gt; belkin
                            [cat] =&gt; Array
                                (
                                    [0] =&gt; electronics
                                    [1] =&gt; connector
                                )

                            [features] =&gt; Array
                                (
                                    [0] =&gt; car power adapter, white
                                )

                            [weight] =&gt; Array
                                (
                                    [0] =&gt; 4
                                )

                            [price] =&gt; Array
                                (
                                    [0] =&gt; 19.95
                                )

                            [popularity] =&gt; Array
                                (
                                    [0] =&gt; 1
                                )

                            [inStock] =&gt; Array
                                (
                                    [0] =&gt; 
                                )

                            [store] =&gt; Array
                                (
                                    [0] =&gt; 45.18014,-93.87741
                                )

                            [manufacturedate_dt] =&gt; 2005-08-01T16:30:25Z
                            [_version_] =&gt; 1510294336458194944
                        )

                    [3] =&gt; SolrObject Object
                        (
                            [id] =&gt; MA147LL/A
                            [name] =&gt; Array
                                (
                                    [0] =&gt; Apple 60 GB iPod with Video Playback Black
                                )

                            [manu] =&gt; Array
                                (
                                    [0] =&gt; Apple Computer Inc.
                                )

                            [manu_id_s] =&gt; apple
                            [cat] =&gt; Array
                                (
                                    [0] =&gt; electronics
                                    [1] =&gt; music
                                )

                            [features] =&gt; Array
                                (
                                    [0] =&gt; iTunes, Podcasts, Audiobooks
                                    [1] =&gt; Stores up to 15,000 songs, 25,000 photos, or 150 hours of video
                                    [2] =&gt; 2.5-inch, 320x240 color TFT LCD display with LED backlight
                                    [3] =&gt; Up to 20 hours of battery life
                                    [4] =&gt; Plays AAC, MP3, WAV, AIFF, Audible, Apple Lossless, H.264 video
                                    [5] =&gt; Notes, Calendar, Phone book, Hold button, Date display, Photo wallet, Built-in games, JPEG photo playback, Upgradeable firmware, USB 2.0 compatibility, Playback speed control, Rechargeable capability, Battery level indication
                                )

                            [includes] =&gt; Array
                                (
                                    [0] =&gt; earbud headphones, USB cable
                                )

                            [weight] =&gt; Array
                                (
                                    [0] =&gt; 5.5
                                )

                            [price] =&gt; Array
                                (
                                    [0] =&gt; 399
                                )

                            [popularity] =&gt; Array
                                (
                                    [0] =&gt; 10
                                )

                            [inStock] =&gt; Array
                                (
                                    [0] =&gt; 1
                                )

                            [store] =&gt; Array
                                (
                                    [0] =&gt; 37.7752,-100.0232
                                )

                            [manufacturedate_dt] =&gt; 2005-10-12T08:00:00Z
                            [_version_] =&gt; 1510294336562003968
                        )

                )

        )

)
</pre></div>
        </div>
  </div>
 </div>

</div></div></div></body></html>